package com.fengmi.mapper;

import com.fengmi.entity.MallGoodsSpec;
import com.fengmi.entity.MallGoodsSpecOptions;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Author 123
 * @Date 2022/2/10 11:17
 * @Version 1.0
 */

public interface GoodsSpecMapper {
    //分页条件查询规格选项和其规格信息
    List<MallGoodsSpecOptions> findSpecOptionsByPage(MallGoodsSpecOptions mallGoodsSpecOptions);

    //保存规格,需要主键返回
    public int insertSpec(MallGoodsSpec mallGoodsSpec);

    //通过规格名称查询规格是否存在
    @Select("select * from mall_goods_spec where spec_name = #{specName}")
    public MallGoodsSpec findMallGoodsSpecBySpecName(String specName);

    //保存规格选项
    public int insertSpecOptions(MallGoodsSpecOptions specOptions);

    //通过规格选项名称查询规格选项是否存在
    @Select("select * from mall_goods_spec_options where option_name = #{optionName}")
    public MallGoodsSpecOptions findMallGoodsSpecOptionsByOptionName(String optionName);

    //通过id查询某个规格选项信息
    public MallGoodsSpecOptions findOneById(String id);

    //修改规格选项信息
    @Update("update mall_goods_spec_options set option_name = #{optionName} " +
            "where id = #{id}")
    public int updateSpecOptions(MallGoodsSpecOptions specOptions);

    //通过id删除规格选项
    @Delete("delete from mall_goods_spec_options where id = #{id}")
    public int deleteOptionsById(String id);

    //查询所有规格
    @Select("select * from mall_goods_spec")
    public List<MallGoodsSpec> findAllSpec();

    //通过规格id查询规格及规格选项
    public MallGoodsSpec findSpecById(String id);

}

